< previous page page_569 next page >

Page 569
Now you can add a bit of code to the form to set up the error handler, and then cause an error to be handled. First, add the following line to the general declaration section of the form. This declares the object that contains the error handler.
Option Explicit
'
Public objErr As Object
Next, add the code from Listing 14.22 to the Form_Load event of the project.
Type.gifListing 14.22. Coding the Form_Load event.
Private Sub Form_Load()
    '
    Data1.DatabaseName = "junk"
    Set objErr = New errHandler
    '
End Sub
This code creates the new error handler object and then sets up the data control with a bogus database name. Now add the code from Listing 14.23 to the Data1_Error event. This code intercepts the database error and displays the new custom dialog box.
Type.gifListing 14.23. Trapping the data control error.
Private Sub Data1_Error(DataErr As Integer, Response As Integer)
    '
   Dim rtn As Long

    Response = 0
    rtn = objErr.errHandler(Errors, errcoll)
    '
End Sub
Now save the form (FRMTEST.FRM) and the project (PRJTEST.VBP) and run the code. You should see your new object library error dialog telling you about the database error (see Figure 14.19).
Now add some code behind the Command1_click event to create a divide-by-zero error. The code in Listing 14.24 does just that.

 
< previous page page_569 next page >

If you like this book, buy it!